package cn.xyy.system.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.xyy.common.domain.mvc.Page;
import cn.xyy.system.dao.NoticeDao;
import cn.xyy.web.AuthUserHolder;
import cn.xyy.common.domain.system.notice.Notice;
import cn.xyy.common.domain.system.notice.NoticeVO;
import cn.xyy.common.exception.SystemException;
import cn.xyy.common.utils.BeanUtils;
import cn.xyy.common.utils.DateUtils;

/**
 * 通知业务层
 * 
 * @author xyy
 *
 */
@Service
public class NoticeService {
	@Autowired
	private NoticeDao noticeDao;

	public Page<Notice> getNoticePage(NoticeVO vo) {
		return noticeDao.selectPage(vo);
	}

	public void insert(Notice vo) {
		vo.setCreator(AuthUserHolder.getUserInfo().getUsername());
		vo.setCreateTime(DateUtils.getDateTime());
		vo.setType(1);
		noticeDao.insert(vo);
	}

	public void update(NoticeVO vo) {
		Notice notice = noticeDao.selectById(vo.getId(), Notice.class);
		if (notice == null) {
			throw new SystemException("未查询到信息");
		}
		BeanUtils.copyProperties(vo, notice);
		notice.setUpdater(AuthUserHolder.getUserInfo().getUsername());
		notice.setUpdateTime(DateUtils.getDateTime());
		noticeDao.update(notice);
	}

	public void delete(String id) {
		noticeDao.delete(new Notice().setId(id));
	}

	public Notice getNoticeInfo(String id) {
		return noticeDao.selectById(id, Notice.class);
	}

}
